






//
//  NXiTongNotiAndWentiFankuiVC.m
//  nncloud
//
//  Created by macfai on 2018/11/29.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NXiTongNotiAndWentiFankuiVC.h"
#import "NSystemNotiCell.h"
#import "NMsgModel.h"
#import "NProblemContentViewController.h"
@interface NXiTongNotiAndWentiFankuiVC ()
<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,strong)NSMutableArray *dataArray;

@property (nonatomic,strong)NSArray *titles;

@end

@implementation NXiTongNotiAndWentiFankuiVC
#define cellIdentifier @"systemnoti"
#define SectionHeaderHeight 15.f

-(UITableView *)tableView{
    
    if (!_tableView) {
        WeakStament(ws);
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 118.0f;
        //        _tableView.separatorColor = [UIColor clearColor];
        _tableView.separatorStyle = 0;
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NSystemNotiCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.dataArray = [NSMutableArray array];
    //系统通知 问题反馈
    if (_atitle) {
        [self.navigationItem setItemWithTitle:_atitle textColor:kNavigationTitleColor fontSize:18 itemType:center];
    }
    
    [self.view addSubview:self.tableView];
    
    [self loadData];
    // Do any additional setup after loading the view.
}


- (void)loadData{
    //如果不传用户ID则messageType
    NSDictionary *dic = @{@"messageUserId":[NUserModel shareInstance].userInfoId,@"messageType":self.msgType,@"size":@(10),@"curPage":@(1)};
    [NNetworkClient getRequestWithBaseUrl:kMsgNotiListUrl setParameters:dic success:^(id responseObject) {
        
        YYLog(@"%@",responseObject);
        WeakStament(ws);
        if ([[responseObject objectForKey:@"code"] integerValue] == 0) {
            
            NSArray *arr = responseObject[@"page"][@"records"];
            YYLog(@"%@",arr);
            for (NSDictionary *dict in arr) {
                NMsgModel *model = [NMsgModel mj_objectWithKeyValues:dict];
                [ws.dataArray addObject:model];
            }
            [ws.tableView reloadData];
        }else{
            [AFToast showText:responseObject[@"msg"]];
        }
    } fail:^(NSError *error) {
        
    } delegater:nil];

    
//    [[NNRCNetRequest manager]getWithUrl:kMsgNotiListUrl params:dic success:^(id result) {
//        YYLog(@"%@",result);
//        WeakStament(ws);
//        if ([[result objectForKey:@"code"] integerValue] == 0) {
//
//            NSArray *arr = result[@"page"][@"records"];
//            YYLog(@"%@",arr);
//            for (NSDictionary *dict in arr) {
//                NMsgModel *model = [NMsgModel mj_objectWithKeyValues:dict];
//                [ws.dataArray addObject:model];
//            }
//            [ws.tableView reloadData];
//
//        }else{
//            [AFToast showText:result[@"msg"]];
//        }
//
//    } failure:^(id failure) {
//
//    }];
}


#pragma mark - datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NMsgModel *model = self.dataArray[indexPath.row];
    NSystemNotiCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.contentLabel.text = model.messageContent;
    cell.timeLabel.text = [ToolKit getTimeFromTimesTamp:model.messageCreateTime];
    if ([_atitle isEqualToString:@"问题反馈"]) {
        cell.QidLabel.hidden = false;
        
    }else{
        cell.QidLabel.hidden = YES;
        cell.topPadding.constant = 15.f;
    }
    cell.QidLabel.text = [NSString stringWithFormat:@"问题编号:%@",model.messageQuestionCode];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
     NMsgModel *model = self.dataArray[indexPath.row];
    if ([_atitle isEqualToString:@"问题反馈"]) {
        NProblemContentViewController *dd = [NProblemContentViewController new];
        dd.problemID = model.messageQuestionId;
        [self.navigationController pushViewController:dd animated:YES];
    }
}


#pragma mark - section head
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionHeaderHeight)];
    view.backgroundColor = kBackgroundColor;
    return view;
}

#pragma mark - section foot
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

@end
